﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CRMWeb.Utilities.Context;
using System.Web.Services;
using CRMBiz;
using CRMEntity;

namespace CRMWeb.Pages
{
    public partial class History : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            hdnUserName.Value = CMSContext.CurrentUser.MemberName;

        }

        [WebMethod()]
        public static void saveNewHistory(string HistoryType, int contactid, string hdate, string htime, string action, string user, string description, int appid)
        {
            try
            {
                HistoryInfo historydata = new HistoryInfo();

                historydata.historyDate = hdate;
                historydata.historyTime = htime;
                historydata.action = action;
                historydata.oprator = user;
                historydata.description = description;

                if (HistoryType == "Contact")
                {
                    historydata.contactID = contactid;
                    historydata.appID = 0;
                    HistoryHandler.AddHistory(historydata);
                }
                else if (HistoryType == "Application")
                {
                    historydata.contactID = 0;
                    historydata.appID = appid;
                    HistoryHandler.AddHistory(historydata);
                }
            }
            catch (Exception ex)
            {
                ErrorHandler.saveErrorLog(ex,CMSContext.CurrentUser.MemberName);
            }
            
        }

        [WebMethod()]
        public static void UpdateHistory(string HistoryType, int historyid, int contactid, string hdate, string htime, string action, string user, string description, int appid)
        {
            try
            {
                HistoryInfo historydata = new HistoryInfo();

                historydata.historyID = historyid;
                historydata.historyDate = hdate;
                historydata.historyTime = htime;
                historydata.action = action;
                historydata.oprator = user;
                historydata.description = description;

                if (HistoryType == "Contact")
                {
                    historydata.contactID = contactid;
                    historydata.appID = 0;
                    HistoryHandler.EditHistory(historydata);
                }
                else if (HistoryType == "Application")
                {
                    historydata.contactID = 0;
                    historydata.appID = appid;
                    HistoryHandler.EditHistory(historydata);
                }
            }
            catch (Exception ex)
            {
                ErrorHandler.saveErrorLog(ex,CMSContext.CurrentUser.MemberName);
            }
        }

    }
}